from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import time
# 自定义Splash类
class MySplash(QWidget):
    def __init__(self):
        super(MySplash, self).__init__()
        self.setAttribute(Qt.WA_TranslucentBackground, True)  # 设置背景透明
        self.setWindowFlags(Qt.FramelessWindowHint)  # 设置无边框
        self.resize(150,50)
        self.text = "初始化程序...0%"
        #self.setGeometry(700, 190, 800, 800)
        self.center()



    def center(self):
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width() - size.width()) / 2,
                  (screen.height() - size.height()) / 2)

    def paintEvent(self, QPaintEvent):
        self.p = QPainter(self)
        self.p.setPen(QPen())
        self.p.setBrush(QBrush())
        #self.p.drawPixmap(0, 0, QPixmap("icons/mysplash.png"))  # 加载自己的图片
        self.p.drawText(QRect(20,5,100,50), Qt.AlignCenter, self.text) #showMesage

    def setText(self, text):
        self.text = text
        self.paintEvent(QPaintEvent)

#启动界面显示时间的设置
def load_Message(splash):
        for i in range(1, 5):  # 显示时间4秒
            time.sleep(1)  # 睡眠
            print(i)
            splash.setText("初始化程序...{0}%".format(25*i))
            splash.update()
            qApp.processEvents()
